<!-- 视频审核 -->
<template>
  <div class="userpage">
    <div class="user-head">
      <div class="search">
        <!-- <el-row
          :gutter="10"
          span="24"
          :type="flex"
          :align="center"
          :justify="space - between"
        > -->
        <el-col :span="10" style="margin-right: 10px">
          <el-input placeholder="请输入邮箱" v-model="Addr" clearable
        /></el-col>
        <el-col :span="10" style="margin-right: 10px">
          <el-input placeholder="请输入地址" v-model="Email" clearable
        /></el-col>
        <el-col :span="6"
          ><template>
            <el-select clearable v-model="IsCheck" placeholder="请选择">
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select> </template
        ></el-col>
        <el-col :span="6"><button @click="search()">查询</button></el-col>
        <!-- </el-row> -->
      </div>
    </div>

    <div class="list-box" id="list-box">
      <el-table
        ref="usersTable"
        :data="list"
        v-loading="loading"
        :height="height"
        style="width: 100%"
        header-row-class-name="headcss"
      >
        <el-table-column
          prop="CreateTime"
          label="注册时间"
          align="center"
        ></el-table-column>
        <el-table-column prop="Addr" label="地址" align="center" width="180">
          <template slot-scope="scope">
            <el-tooltip
              class="item"
              effect="dark"
              :content="scope.row.Addr"
              placement="top"
            >
              <p style="cursor: pointer">{{ addrStr(scope.row.Addr, 8) }}</p>
            </el-tooltip>
          </template>
        </el-table-column>
        <el-table-column
          prop="Email"
          label="邮箱"
          align="center"
          width="190"
        ></el-table-column>
        <el-table-column
          prop="CreateTime"
          label="查看视频"
          align="center"
          width="180"
        >
          <template slot-scope="scope">
            <el-link
              :underline="false"
              @click="setCheckBoxChange(true, scope.row)"
              >查看视频</el-link
            >
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" align="center" width="256">
          <template slot-scope="scope">
            <el-button
              @click.native.prevent="handelCheckVideo(1001, scope.row.Email)"
              type="text"
              size="medium"
            >
              通过
            </el-button>
            <el-button
              @click.native.prevent="handelCheckVideo(1002, scope.row.Email)"
              type="text"
              size="medium"
            >
              驳回
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="page-limit">
      <el-pagination
        @size-change="SizeChange"
        @current-change="CurrentChange"
        :current-page="currentPage"
        :page-sizes="[15, 50, 100, 200]"
        :page-size="size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>

    <el-dialog title="查看视频" :visible.sync="dialogVisible" width="30%">
      <div class="center">
        <video class="video" autoplay controls :src="selectedItemVideo"></video>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { getCheckVideoList, checkVideo } from "@/utils/api";
export default {
  data() {
    return {
      currentPage: 1,
      size: 15,
      total: 0,
      height: "100%",
      loading: false,
      list: [],
      type: 1,
      content: "",
      doArry: [],
      dialogVisible: false,
      selectedItem: {},
      selectedItemVideo:'',
      options: [
        { label: "审核通过", value: 1001 },
        { label: "审核失败", value: 1002 },
      ],
      Addr: "",
      IsCheck: "",
      Email: "",
    };
  },
  mounted() {
    this.fetchData();
  },
  methods: {
    // 基础查询
    async fetchData(datas) {
      let params = {
        Addr: this.Addr,
        Email: this.Email,
        IsCheck: this.IsCheck ? this.IsCheck : 1000,
        Size: this.size,
        Limit: this.currentPage - 1,
        ...datas,
      };
      this.loading = true;
      let { data, response } = await getCheckVideoList(params);
      let { total, dataList } = data;
      this.loading = false;
      this.total = total;
      this.list = dataList;
    },
    async search() {
      this.fetchData();
      this.loading = true;
    },
    //查询当日新注册用户
    async getTodayRegist(type) {
      this.type = type;
      let params = {
        option: "userbase-today",
        size: this.size,
        page: this.currentPage - 1,
      };
      this.loading = true;
      let { data, response } = await getUsersBase(params);
      let { total, dataList } = data;
      this.loading = false;
      this.total = total;
      this.list = dataList;
    },
    SelectionChange(val) {
      this.doArry = val;
    },
    SizeChange(size) {
      this.size = size;
      this.currentPage = 1;
      if (this.type == 1) {
        this._getUsersBase();
      } else {
        this.getTodayRegist("2");
      }
    },
    CurrentChange(page) {
      this.currentPage = page;
      if (this.type == 1) {
        this._getUsersBase();
      } else {
        this.getTodayRegist("2");
      }
    },
    setCheckBoxChange(result, value) {
      console.log(value);
      this.dialogVisible = result;
      const url =
        "http://152.32.175.105:8082/static/video/" + value.Email + ".mp4";
      console.log(url);
      this.selectedItemVideo = url;
    },

    async handelCheckVideo(IsSore, Email) {
      const params = {
        Email,
        IsSore,
      };
      const res = await checkVideo(params);
      if (res.data === "OK") {
        IsSore === 1001
          ? this.$message({ type: "success", message: "审核成功!" })
          : this.$message({ type: "success", message: "驳回成功!" });
        this.fetchData();
      }
      console.log(res);
    },
    openIncome(addr) {
      this.$refs.income.open(addr);
    },
    addrStr(str, num) {
      if (str) {
        if (num) {
          return (
            str.substring(0, num) +
            "..." +
            str.substring(str.length - num, str.length)
          );
        } else {
          return (
            str.substring(0, 10) +
            "..." +
            str.substring(str.length - 10, str.length)
          );
        }
      } else {
        return str;
      }
    },
  },
};
</script>

<style scoped lang="scss">
.userpage {
  padding: 20px 20px 10px 20px;
  height: 100%;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.video {
  height: 400px;
}
.list-box {
  flex: 1;
  overflow-y: scroll;
}
.page-limit {
  display: flex;
  justify-content: center;
  padding-top: 10px;
}
.user-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 20px;
}
.stsr {
  color: #2389fe;
  font-weight: bolder;
  margin: 0 4px;
  font-size: 16px;
}
.center {
  display: flex;
  justify-content: center;
  align-items: center;
}
.search {
  display: flex;
  align-items: center;
  width: 320px;
  justify-content: space-between;
  width: 100%;

  input {
    width: 200px;
  }

  button {
    width: 90px;
    height: 40px;
    background: #2389fe;
    border-radius: 5px;
    color: #fff;
    margin-left: 10px;
    &:active {
      opacity: 0.8;
    }
  }
}
.user-do {
  display: flex;
  align-items: center;
  .btn1 {
    width: 70px;
    height: 40px;
    background: rgba(211, 12, 63, 0.99);
    border-radius: 5px;
    color: #fff;
    &:active {
      opacity: 0.8;
    }
  }
  .btn2 {
    width: 70px;
    height: 40px;
    background: #2389fe;
    border-radius: 5px;
    color: #fff;
    margin: 0 10px;
    &:active {
      opacity: 0.8;
    }
  }
  .btn3 {
    width: 171px;
    height: 40px;
    border-radius: 5px;
    border: 1px solid #2389fe;
    color: #2389fe;
    background: #fff;
    &:active {
      border: 1px solid #15549d;
      color: #15549d;
    }
  }
}
.page-title {
  display: flex;
  align-items: center;
  padding-bottom: 20px;

  p {
    margin-left: 10px;
    font-size: 24px;
    color: #333333;
  }

  img {
    width: 24px;
  }
}
</style>
<style>
.el-table {
  border-radius: 5px;
}
.el-table th.el-table__cell {
  background-color: #2389fd !important;
  color: #fff;
}
.el-table--striped .el-table__body tr.el-table__row--striped td.el-table__cell {
  background: #deeeff !important;
}
.el-table td.el-table__cell {
  border: none;
}
.inp .el-input__inner {
  border: none;
  padding-left: 0;
}
</style>
